<?php

/**
 * Invoice filter form base class.
 *
 * @package    erpcrm
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseInvoiceFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'customer_iden'        => new sfWidgetFormPropelChoice(array('model' => 'Contact', 'add_empty' => true)),
      'invoice_type'         => new sfWidgetFormPropelChoice(array('model' => 'ListDocumentTypes', 'add_empty' => true, 'key_method' => 'getTypeid')),
      'invoice_id'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'terms_name'           => new sfWidgetFormPropelChoice(array('model' => 'ListInvoiceTerms', 'add_empty' => true, 'key_method' => 'getTerm')),
      'days_due'             => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'remarks'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'delivery_details'     => new sfWidgetFormFilterInput(),
      'invoice_name'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'delivery_mode'        => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'delivery_date'        => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'vat_excempt_type'     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'payment_invoice_list' => new sfWidgetFormPropelChoice(array('model' => 'Payment', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'customer_iden'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Contact', 'column' => 'iden')),
      'invoice_type'         => new sfValidatorPropelChoice(array('required' => false, 'model' => 'ListDocumentTypes', 'column' => 'typeid')),
      'invoice_id'           => new sfValidatorPass(array('required' => false)),
      'terms_name'           => new sfValidatorPropelChoice(array('required' => false, 'model' => 'ListInvoiceTerms', 'column' => 'term')),
      'days_due'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'remarks'              => new sfValidatorPass(array('required' => false)),
      'delivery_details'     => new sfValidatorPass(array('required' => false)),
      'invoice_name'         => new sfValidatorPass(array('required' => false)),
      'delivery_mode'        => new sfValidatorPass(array('required' => false)),
      'delivery_date'        => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDate(array('required' => false)))),
      'vat_excempt_type'     => new sfValidatorPass(array('required' => false)),
      'payment_invoice_list' => new sfValidatorPropelChoice(array('model' => 'Payment', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('invoice_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addPaymentInvoiceListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(PaymentInvoicePeer::INVOICE_IDEN, InvoicePeer::INVOICE_IDEN);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(PaymentInvoicePeer::PAYMENT_IDEN, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(PaymentInvoicePeer::PAYMENT_IDEN, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Invoice';
  }

  public function getFields()
  {
    return array(
      'invoice_iden'         => 'ForeignKey',
      'customer_iden'        => 'ForeignKey',
      'invoice_type'         => 'ForeignKey',
      'invoice_id'           => 'Text',
      'terms_name'           => 'ForeignKey',
      'days_due'             => 'Number',
      'remarks'              => 'Text',
      'delivery_details'     => 'Text',
      'invoice_name'         => 'Text',
      'delivery_mode'        => 'Text',
      'delivery_date'        => 'Date',
      'vat_excempt_type'     => 'Text',
      'payment_invoice_list' => 'ManyKey',
    );
  }
}
